In [5]:
import sys
sys.path.append('../exercises')
import sample_module
sample_module.sample_function()
In [6]:
from sample_module import sample_function as samp_func
samp_func()
Now create a module called mymodule (i.e. mymodule.py) using the text editor functionality of Jupyter Notebooks.
Add the following code to the module.
def add(a, b):
return a + b
Save the file and import your newly created module in the cell below.
If you want you can also use a more inventive name than mymodule.py.
In [ ]:
In [ ]:
Python keeps track of modules that are imported, and performs the actual import only with the first import mymodule
statement. If a module is modified during an interactive session, module needs to be explicitly reloaded in order to changes take effect. Reloading can be done with the function reload
in the built-in module importlib
:
In [ ]:
from importlib import reload
reload(mymodule)